<template>
    <view class="mine">
        <view class="topbg">
            <view class="cards">
                <navigator url="../persondata/persondata" hover-class="none">
                    <image class="photos" :src="photoImg"></image>
                </navigator>
                <view class="texl">
                    <view class="naickv">
                        <view class="nicker">用户名: {{nickNames}}</view>
                        <!-- 根据用户等级，v1 和 he.png不同时显示 -->
                        <image v-if="userLevels=='1'" class="vipstep" src="../../static/img/v1.png"></image>
                        <image v-else-if="userLevels=='2'" class="vipstep" src="../../static/img/v2.png"></image>
                        <image v-else-if="userLevels=='3'" class="vipstep" src="../../static/img/v3.png"></image>
                        <image v-else-if="userLevels=='4'" class="vipstep" src="../../static/img/v4.png"></image>
                    </view>
                    <view class="usertel">
                       用户id: {{userId}}
                    </view>
                </view>
                <view class="" style="width: 110rpx;">
                    <!-- 根据用户等级，v1 和 he.png不同时显示 -->
                    <image v-if="userLevels=='5'" class="heimg" src="../../static/img/he.png"></image>
                </view>
                <view class="seticwont">
                    <navigator url="../mineset/mineset" hover-class="none">
                        <image class="seticon" src="../../static/img/sets.png"></image>
                        <view class="setbtnl">设置</view>
                    </navigator>
                </view>
            </view>
            <view class="shownumber">
                <!-- <view class="asset" style="width:260rpx">
					<view style="font-family: Aileron;font-weight: bold;font-size: 16;">{{allzich}}</view>
					<view class="botmwen">
                        总资产折合(USDT)
                    </view>
                </view>
                <view class="xians"></view> -->
                <view class="asset" style="width:100%">
					<view style="font-family: Aileron;font-weight: bold;font-size: 16;">{{dcard}}</view>
                    <view class="botmwen">
                        点卡余额(当前抵扣率:{{ myPointRatioPercentage }})
                    </view>
                </view>
            </view>
        </view>
		<view class="pointnote">
			点卡的用途：
			    <br/>
			    - 用于抵扣账单，每次平仓若盈利则扣除该笔利润的{{ myPointRatioPercentage }}的点卡数量。
			    <br/>
			    - 若亏损则不扣除点卡
				<br/>
				- 点卡若不足则无法操作机器人。
		</view>
        <view class="twoimg">
            <view>
                <navigator url="../apiautho/apiautho" hover-class="none">
                    <image src="../../static/img/modulba.png"></image>
                </navigator>
            </view>
            <view>
                <navigator url="../bill/bill" hover-class="none">
                    <image src="../../static/img/modulbb.png"></image>
                </navigator>
            </view>
        </view>
        <!-- <view class="modulminetwo">
            <view class="fvs">
                <navigator url="../chargemoney/chargemoney" hover-class="none">
                    <image src="../../static/img/fv1.png"></image>
                    <view>充币</view>
                </navigator>
            </view>
            <view class="fvs">
                <view @click="tibis">
                    <image src="../../static/img/fv2.png"></image>
                    <view>提币</view>
                </view>
            </view>
            <view class="fvs">
                <view @click="hzhuan">
                    <image src="../../static/img/fv3.png"></image>
                    <view>互转</view>
                </view>
            </view>
            <view class="fvs">
                <navigator url="../exchangecard/exchangecard" hover-class="none">
                    <image src="../../static/img/fv4.png"></image>
                    <view>兑换点卡</view>
                </navigator>
            </view>
        </view> -->
        <!-- <view class="minela">
            <navigator url="../assetrecord/assetrecord" hover-class="none">
                <view>
                    <image class="leftimge" src="../../static/img/zx1.png"></image>
                    <text>资产记录</text>
                </view>
                <image class="rightarrow" src="../../static/img/arrowright.png"></image>
            </navigator>
        </view> -->
        <view class="minela">
            <navigator url="../transrecord/transrecord?a=1" hover-class="none">
                <view>
                    <image class="leftimge" src="../../static/img/zx2.png"></image>
                    <text>交易记录</text>
                </view>
                <image class="rightarrow" src="../../static/img/arrowright.png"></image>
            </navigator>
        </view>
		<!-- <view class="minela">
		    <navigator url="../defaultset/defaultset" hover-class="none">
		        <view>
		            <image class="leftimge" src="../../static/img/defaultset.png"></image>
		            <text>高级配置</text>
		        </view>
		        <image class="rightarrow" src="../../static/img/arrowright.png"></image>
		    </navigator>
		</view> -->
        <view class="minela">
            <navigator url="../community/community" hover-class="none">
                <view>
                    <image class="leftimge" src="../../static/img/zx3.png"></image>
                    <text>我的社区</text>
                </view>
                <image class="rightarrow" src="../../static/img/arrowright.png"></image>
            </navigator>
        </view>
        <!-- <view class="minela">
            <navigator url="../invitefriend/invitefriend" hover-class="none">
                <view>
                    <image class="leftimge" src="../../static/img/zx4.png"></image>
                    <text>邀请好友</text>
                </view>
                <image class="rightarrow" src="../../static/img/arrowright.png"></image>
            </navigator>
        </view> -->
        <!-- <view class="minela">
            <navigator url="../rankinglist/rankinglist" hover-class="none">
                <view>
                    <image class="leftimge" src="../../static/img/zx5.png"></image>
                    <text>排行榜单</text>
                </view>
                <image class="rightarrow" src="../../static/img/arrowright.png"></image>
            </navigator>
        </view> -->
        <view class="minela">
            <navigator url="../customser/customser" hover-class="none">
                <view>
                    <image class="leftimge" src="../../static/img/zx6.png"></image>
                    <text>联系我们</text>
                </view>
                <image class="rightarrow" src="../../static/img/arrowright.png"></image>
            </navigator>
        </view>
        <!-- <view class="minela">
            <navigator url="../aboutwe/aboutwe" hover-class="none">
                <view>
                    <image class="leftimge" src="../../static/img/zx7.png"></image>
                    <text>关于我们</text>
                </view>
                <image class="rightarrow" src="../../static/img/arrowright.png"></image>
            </navigator>
        </view> -->
    </view>
</template>

<script>
    let uinfo;
    import request from "../../untils/request.js";
    export default {
		components: {
		},
		computed:{
			myPointRatioPercentage() {
			      return (this.myPointRatio * 100).toFixed(1) + '%';
		    },
		},
        data() {
            return {
                isHe: false,
                nickNames: '',
                photoImg: '',
                userNum: '',
                allzich: '',
                dcard: '',
                userLevels: '',
				myPointRatio: 0, 
				userId: ''
            }
        },
        onLoad() {

        },
        onShow() {
            uinfo = uni.getStorageSync('userInfo');

            this.poinCard();
            this.personListfn();
        },
        onPullDownRefresh() {
            console.log('refresh');

            this.poinCard();
            this.personListfn();
        },
        methods: {
            //提币
            tibis(){
                request.postMember('/user/info/queryUserInfo', {
                    userId: uinfo.userId,
                }).then(res => {
                    if (res.code == '200') {
                        //是否设置支付密码  isSetPayPwd 0未设置   1已设置
                        if (res.data.isSetPayPwd == 0) {
                            uni.showToast({
                                icon: "none",
                                title: '请先设置支付密码',
                            });
                            setTimeout(function() {
                                uni.navigateTo({
                                    url: '/pages/editpaypad/editpaypad?ab=1',
                                });
                            }, 1000)
                
                        } else {
                            uni.navigateTo({
                                url: '/pages/timoney/timoney',
                            });
                            console.log('已设置支付密码')
                        }
                    }
                })
            },
            //互转，判断是否设置支付密码
            hzhuan() {
                request.postMember('/user/info/queryUserInfo', {
                    userId: uinfo.userId,
                }).then(res => {
                    if (res.code == '200') {
                        //是否设置支付密码  isSetPayPwd 0未设置   1已设置
                        if (res.data.isSetPayPwd == 0) {
                            uni.showToast({
                                icon: "none",
                                title: '请先设置支付密码',
                            });
                            setTimeout(function() {
                                uni.navigateTo({
                                    url: '/pages/editpaypad/editpaypad?ab=1',
                                });
                            }, 1000)

                        } else {
                            uni.navigateTo({
                                url: '/pages/conversion/conversion',
                            });
                            console.log('已设置支付密码')
                        }
                    }
                })
            },
            //用户信息
            personListfn() {
                request.postMember('/user/info/queryUserInfo', {
                    userId: uinfo.userId,
                }).then(res => {
                    if (res.code == '200') {
                        console.log(res.data)
                        uinfo.userId=res.data.userId;
                        uinfo.userLoginInfo.userId=res.data.userId;
                        uinfo.userLoginInfo.mobile=res.data.mobile;
                        //更新缓存，是否激活
                        uinfo.userLoginInfo.isActive = res.data.isActive;

                        uni.setStorageSync('userInfo',uinfo);
                        this.userId = uinfo.userId
                        //是否绑定手机号mobile  null未绑定
                        /* if (res.data.mobile == null) {
                            uni.showToast({
                                icon: "none",
                                title: '请先绑定手机号',
                            })
                            uni.navigateTo({
                                url: '/pages/bindtel/bindtel',
                            })
                        } else {
                            console.log('已绑定')
                        } */

                        uni.stopPullDownRefresh();
                        this.nickNames = res.data.nickname;
                        this.photoImg = res.data.avatar;
                        this.userLevels = res.data.userLevel;
                        if (res.data.email == null) {
                            this.userNum = res.data.mobile;
                        } else {
                            this.userNum = res.data.email;
                        }
                    } else {
                        uni.stopPullDownRefresh();
                        uni.showToast({
                            icon: "none",
                            title: res.message,
                        });
                    }
                })
            },
            //资产，点卡
            poinCard() {
                request.postAssets('/assets/userWalletInfo/queryUserWalletInfo', {
                    sortAttribute: '3',
                    sortType: 'descend',
                    userId: uinfo.userId
                }).then(res => {
					console.log(res)
                    if (res.code == '200') {
                        uni.stopPullDownRefresh();
                        if (res.data.items != '') {
                            function substr(str){
                                var s = str + "";
                                if(s.indexOf(".")!='-1'){
                                    var str = s.substring(0,s.indexOf(".") + 4);
                                }
                                return str
                            }
                            console.log(res.data.items[0].avaliableBalance)
                            console.log(res.data.items[0].frozenBalance)
                            
                            this.allzich = Number(res.data.items[0].avaliableBalance) + Number(res.data.items[0].frozenBalance);
                            console.log(this.allzich)
                            console.log(this.allzich)
                            this.dcard = res.data.items[0].pointBalance;
                            this.dcard =substr(this.dcard )
							this.myPointRatio = res.data.items[0].myPointRatio;
                        }
                    } else {
                        uni.stopPullDownRefresh();
                        uni.showToast({
                            icon: "none",
                            title: res.message,
                        });
                    }
                })
            }
        }
    }
</script>

<style>
    .mine {
        background: #F5F5F5;
        padding: 0 0 50px 0;
    }

    .cards {
        display: flex;
        align-items: center;
    }

    .cards .photos {
        width: 130rpx;
        height: 130rpx;
        margin: 68rpx 0 0 40rpx;
        border: 1px solid #FFFFFF;
        border-radius: 50%;
    }

    .cards .texl {
        margin: 38px 0 0 10px;
    }

    .cards .seticwont {
        margin: -20px 0 0 10px;
    }

    .cards .texl .nicker {
        font-size: 18px;
        font-family: Source Han Sans CN;
        font-weight: 400;
        line-height: 20px;
        color: #FFFFFF;
        margin: 0 0 10rpx 0;
    }

    .cards .texl .vipstep {
        width: 37px;
        height: 24px;
    }

    .cards .texl .naickv {
        display: flex;
        width: 290rpx;
    }

    .cards .texl .usertel {
        font-size: 14px;
        font-family: Aileron;
        font-weight: 400;
        line-height: 20px;
        color: #FFFFFF;
    }

    .cards .heimg {
        width: 87rpx;
        height: 69rpx;
        margin: 38px 0 0 10px;
    }

    .cards .seticon {
        width: 23px;
        height: 20px;
    }

    .cards .setbtnl {
        font-size: 12px;
        font-family: Source Han Sans CN;
        font-weight: 400;
        line-height: 20px;
        color: #FFFFFF;
    }

    .topbg {
        width: 710rpx;
        height: 380rpx;
        background: url('../../static/img/mybg.png') no-repeat;
        background-size: 100% 100%;
        margin: 0 auto 20px;
        border-radius: 10px;
        box-shadow: 0px 1px 10px 2px rgba(0, 0, 0, 0.3);
    }


    /* #ifndef APP-PLUS */
    .shownumber {
        width: 580rpx;
        height: 85px;
        margin: 15rpx auto 0;
        border-radius: 10px 10px 0px 0px;
        display: flex;
        justify-content: space-between;
        align-items: center;
        background-color: #FFFFFF;
        padding: 0 20rpx;
    }

    /* #endif */
    /* #ifdef APP-PLUS */
    .shownumber {
        width: 580rpx;
        height: 70px;
        margin: 22rpx auto 0;
        border-radius: 10px 10px 0px 0px;
        display: flex;
        justify-content: space-between;
        align-items: center;
        background-color: #FFFFFF;
        padding: 0 20rpx;
		position: relative;
    }

    /* #endif */

    .shownumber .xians {
        width: 1px;
        height: 80rpx;
        background-color: #F1F2F6;
    }

    .shownumber .wepubs {
        font-size: 20px;
        font-family: Aileron;
        font-weight: 600;
        line-height: 20px;
        color: #000000;
        margin: 8px 0 0 0;
    }

    .shownumber .botmwen {
        font-size: 12px;
        font-family: Source Han Sans CN;
        font-weight: 400;
        line-height: 20px;
        color: #838AA4;
        margin: 8px 0 0 0;
    }

    .modulminetwo {
        width: 710rpx;
        height: 100px;
        background: #FFFFFF;
        margin: 0 auto 40rpx;
        border-radius: 6px;
        display: flex;
        justify-content: space-around;
        align-items: center;
    }

    .modulminetwo .fvs {
        text-align: center;
    }

    .modulminetwo .fvs image {
        width: 72rpx;
        height: 72rpx;
    }

    .modulminetwo .fvs view {
        font-size: 12px;
        font-family: Source Han Sans CN;
        font-weight: 400;
        line-height: 20px;
        color: #333333;
    }

    .minela {
        width: 710rpx;
        height: 108rpx;
        background: #FFFFFF;
        margin: 0 auto 20rpx;
        border-radius: 6px;
    }

    .minela navigator {
        display: flex;
        height: 108rpx;
        align-items: center;
        margin: 0 60rpx 0 40rpx;
        justify-content: space-between;
    }

    .minela .leftimge {
        width: 40rpx;
        height: 40rpx;
        vertical-align: -10rpx;
        margin: 0 10rpx 0 0;
    }

    .minela text {
        font-size: 16px;
        font-family: Source Han Sans CN;
        font-weight: 500;
        line-height: 27px;
        color: #333333;
    }

    .minela .rightarrow {
        width: 14rpx;
        height: 22rpx;
    }

    .twoimg {
        display: flex;
        justify-content: space-between;
        margin: 0 24rpx 14px 24rpx;
    }

    .twoimg image {
        width: 344rpx;
        height: 160rpx;
    }
	
	.asset{
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}
	
	.pointnote {
	    background-color: #fff;
	    border: 1px solid #ddd; /* 添加边框，使内容更突出 */
	    border-radius: 8px;
	    padding: 15px;
	    margin-bottom: 20px;
	    font-size: 16px;
	    color: #333;
	    line-height: 1.5; /* 控制行间距 */
	    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); /* 添加轻微阴影 */
	  }
</style>
